# 学生类
class Student:
    def __init__(self, name, score):
        # 构造方法
        # 实例变量
        self.name = name
        self.score = score

    def __str__(self):
        """将输出格式 打印成 字符串"""
        return f"{self.name} {self.score}"

    def coding(self):
        print(f"{self.name}会编码")

    def playing(self):
        print("正在打游戏")

'''学员管理系统'''

class StudentManage:
    def __init__(self):
         self.students = []


    def append_student(self,student):
        '''新增学员'''
        print(student)
        self.students.append(student)
        print('添加成功')



    def delete_student(self,name):
        n=0
        x=0
        for i in self.students:
             if i.name == name:
                 del self.students[n]
                 print('删除成功')
                 x=1
             n+=1
        if x == 0:
            print('没有找到')

    def get_student_info(self, name):
        n = 0
        x = 0
        for i in self.students:
            if i.name == name:
                print(i)
                x=1
            n += 1
        if x == 0:
            print('没有找到')




    def get_average_score(self):
        n = 0
        sum = 0
        for item in self.students:
            sum+=item.score
            n+=1
        if n == 0:
            print('没有学生')
        else:
            print(sum/n)


ctrl = True
student_manage = StudentManage()
while ctrl:
    print('*************')
    print("1.添加学生\n2.删除学生\n3.查询学生\n4.计算平均分\n5.退出")
    print('*************')
    num = int(input('请选择你的操作'))


    if num == 1 :
        mark = True
        while mark:
            name = input('请输入姓名')
            score = int(input('请输入成绩'))
            stu = Student(name,score)
            student_manage.append_student(stu)
            judge = input('是否继续（y/n）:')
            if judge == 'y':
                mark = True
            else:
                mark = False
    elif num == 2:
        mark = True
        while mark:
            name = input('请输入你要删除的学生的姓名')
            student_manage.delete_student(name)
            judge = input('是否继续（y/n）:')
            if judge == 'y':
                mark = True
            else:
                mark = False
    elif num == 3:
        mark = True
        while mark:
            name = input('请输入你要查询的学生的姓名')
            student_manage.get_student_info(name)
            judge = input('是否继续（y/n）:')
            if judge == 'y':
                mark = True
            else:
                mark = False
    elif num == 4:
        student_manage.get_average_score()
    else:
        ctrl = False
        print('你退出学生管理系统')










